package jmx.study.mbean;

import java.lang.management.ManagementFactory;

import javax.management.MBeanServer;
import javax.management.ObjectName;

import com.sun.jdmk.comm.HtmlAdaptorServer;

/**
 * MBean接入层:内置的两种本地访问 方式 jconsole、html
 * @author zhenzhen
 *
 */
public class HelloAgent {
   
    public static void main(String[] args)  throws Exception {
        //1 获取MBeanServer，用来做MBean的容器
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();

        //2 ObjectName是 MBean的唯一标识. 命名规范:[域名:name=MBean名称] 域名和MBean的名称可以任意取.
        ObjectName helloName = new ObjectName("jmxstudy:name=hello");

        //3 将mbean注入MBeanServer,注入时需要创建一个ObjectName类
        server.registerMBean(new Hello(), helloName);

        //用html方式访问
//        ObjectName adapterName = new ObjectName("jmxstudy:name=htmladapter,port=8082");
//        HtmlAdaptorServer adapter = new HtmlAdaptorServer();
//        server.registerMBean(adapter, adapterName);
//        adapter.start();
        Thread.sleep(Integer.MAX_VALUE);
        System.out.println("HelloAgent start...");
    }


}
